//
//  OffLineViewController.m
//  TableViewGroup
//
//  Created by 侯振兴 on 15/1/6.
//  Copyright (c) 2015年 侯振兴. All rights reserved.
//

#import "OffLineViewController.h"

@interface OffLineViewController ()

@end

@implementation OffLineViewController

- (void)dealloc
{
    [_tableArray release];
    [super dealloc];
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.tableArray = [NSMutableArray array];
        self.arr2 = [NSMutableArray array];
        
        NSMutableDictionary *dic1 = [NSMutableDictionary dictionary];
        [dic1 setObject:@"仅Wifi下载" forKey:@"name"];
    
        
        NSMutableDictionary *dic2 = [NSMutableDictionary dictionary];
        [dic2 setObject:@"允许离线正文图片" forKey:@"name"];
        
        NSMutableDictionary *dic3 = [NSMutableDictionary dictionary];
        [dic3 setObject:@"离线文章数量" forKey:@"name"];
        
        NSArray *arrayL = [NSArray arrayWithObjects:@"精品", @"转藏", @"社会", @"政治", @"历史", @"文化", @"财经", @"科学", @"健康", @"生活", @"美容", @"美食", @"家局", @"育儿", @"星座", @"休闲", @"情感", @"心灵", @"幽默", @"美文", @"教育", @"职场", @"电脑", @"爱车", @"旅游", @"摄影", @"艺术", @"美图", @"原创", nil];
        
            for (int i = 0; i < 29; i++) {
                NSMutableDictionary *dic4 = [NSMutableDictionary dictionary];
                [dic4 setObject:[arrayL objectAtIndex:i] forKey:@"name"];
                
                [self.arr2 addObject:dic4];
            }
        
        
        NSMutableArray *arr1 = [[NSMutableArray array] init];
        [arr1 addObject:dic1];
        [arr1 addObject:dic2];
        [arr1 addObject:dic3];
        
        NSMutableDictionary *bigDic1 = [NSMutableDictionary dictionary];
        [bigDic1 setObject:arr1 forKey:@"array"];
        [bigDic1 setObject:@"     " forKey:@"title"];
        
        NSMutableDictionary *bigDic2 = [NSMutableDictionary dictionary];
        [bigDic2 setObject:_arr2 forKey:@"array"];
        [bigDic2 setObject:@"请勾选想下载的分类" forKey:@"title"];
        
        [_tableArray addObject:bigDic1];
        [_tableArray addObject:bigDic2];
        
    }
    
    return self;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"离线下载设置";
    [self createOffLine];
}


- (void)createOffLine
{
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 100) style:UITableViewStyleGrouped];
    _tableView.dataSource = self;
    _tableView.delegate = self;
    [self.view addSubview:_tableView];
    [_tableView release];
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return [_tableArray count];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSDictionary *dic = [_tableArray objectAtIndex:section];
    NSArray *array = [dic objectForKey:@"array"];
    return [array count];
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *celld = @"cell3";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:celld];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:celld];
        
    }
    NSDictionary *secDic = [_tableArray objectAtIndex:indexPath.section];
    NSArray *array = [secDic objectForKey:@"array"];
    NSDictionary *dic = [array objectAtIndex:indexPath.row];
    NSString *name = [dic objectForKey:@"name"];
    cell.textLabel.text = name;
    return cell;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    NSDictionary *dic = [_tableArray objectAtIndex:section];
    NSString *title = [dic objectForKey:@"title"];
    return title;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
